package com.bigshen.demo.annotation.configurecomponents.a5Imports;

import com.bigshen.demo.project.Cat;
import com.bigshen.demo.project.entity.Person;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import(value = {Cat.class, MyImport.class, MyRegistry.class})
public class MyConfig {

    /**
     *
     * 注册Bean的几种方式
     * 1. @Bean 导入单个Bean
     * 2. @ComponentScan (默认扫描 @Controller、@Service、@Repository、@Component)
     * 3. @Import 快速导入Bean
     *      a. @Import 直接参数导入
     *      b. 实现 ImportSelector 自定义规则实现
     *      c. 实现 ImportBeanDefinitionRegistrar 直接往IOC容器中注册
     * 4. FactoryBean ， 把需要注册的对象封装为FactoryBean
     *      a. FactoryBean 负责将Bean注册到Ioc的Bean
     *      b. BeanFactory Ioc容器，从中获得Bean对象
     * @return
     */
    @Bean
    public Person person() {
        return new Person("shen", "19");
    }

    @Bean
    public FactoryBean world() {
        return new MyFactoryBean();
    }

}
